package com.fraud.job;

import java.util.Date;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.log4j.Logger;

import com.fraud.bean.FileCollectorBean;

@Singleton
@Startup
public class FileCollectorJob {

	private final Logger logger = Logger.getLogger(FileCollectorJob.class);

	@PersistenceContext
	EntityManager entityManager;

	@EJB
	FileCollectorBean fileCollectorBean;

	// TODO buradaki ayarın configurasyona tasinması lazım
	@Schedule(hour = "3", minute = "1", second="1", persistent = false)
	public void run() {

		try {

			Date date = new Date();
			date.setDate(date.getDate() - 1);

			logger.info("This job starting.");

			fileCollectorBean.collectFiles(date,null);

			logger.info("This job finished.");

		} catch (Exception e) {
			logger.error("Hata", e);
		}
	}
}
